#include "WOPEvent.h"
#include "InterpolationProcessor.h"
#include "ConvertValueToString.h"

void WOPEvent::writePastValueToVariation(){
	this->_variation = this->_past_value;
	this->_WOP_variation = Ogre::StringConverter::parseReal(this->_past_value);
}
void WOPEvent::generateInterpolation(){
	InterpolationProcessor ipp;
	
	Ogre::Real pastvalue = Ogre::StringConverter::parseReal(this->_past_value);
	Ogre::Real currentvalue = Ogre::StringConverter::parseReal(this->_current_value);		
	
	double ipvalue = ipp.excution((double)pastvalue,(double)currentvalue);
	this->_ipValue = ConvertValueToString::DoubletoString(ipvalue);
	this->_WOP_variation = (double)Ogre::StringConverter::parseReal(this->_past_value);
}

bool WOPEvent::checkBounding(){
	double wop_ipvalue = (double)Ogre::StringConverter::parseReal(this->_ipValue);
	if(wop_ipvalue != 0.0){
		this->_WOP_variation+= wop_ipvalue;
		double wop_bound = (double)Ogre::StringConverter::parseLong(this->_current_value);
		if(isOverflow(this->_WOP_variation,wop_bound,wop_ipvalue)){
			return false;
		}
	}
	this->_variation = ConvertValueToString::DoubletoString(this->_WOP_variation);
	return true;
}

bool WOPEvent::checkInterpolationValueIsZero(){
	Ogre::Real ipvalue = Ogre::StringConverter::parseReal(this->_ipValue);
	if(ipvalue == 0.0){
		return true;
	}
	return false;
}

void WOPEvent::recover(){
	writePastValueToVariation();
	this->_ipValue = "0.0";
	this->_WOP_variation = (double)Ogre::StringConverter::parseReal(this->_past_value);
}